package com.xiaokang.service.impl;

import java.util.List;

import com.xiaokang.dao.IFlightDao;
import com.xiaokang.pojo.Plane;
import com.xiaokang.service.IFlightService;
import com.xiaokang.utils.DateUtils;

/**
 * 
 * @Description: 业务层
 * @author 小康
 * @version V1.0.0 2019年11月10日 上午8:01:36
 */
public class FlightServiceImpl implements IFlightService {
	private IFlightDao flightDao;

	@Override
	public List<Plane> selectFlight() {
		List<Plane> planes = flightDao.selectFlight();
		return planes;
	}

	@Override
	public List<Plane> queryFlight(String departureCity, String arrivalCity) {
		List<Plane> planes = flightDao.queryFlight(departureCity, arrivalCity);
		return planes;
	}

	@Override
	public String addFight(String flightNo, String departureCity, String departureTime, String arrivalCity,
			String arrivalTime) {
		String tips = "";
		Plane plane = new Plane(flightNo, departureCity, arrivalCity, DateUtils.parseStringToDate(departureTime),
				DateUtils.parseStringToDate(arrivalTime));
		int rows = flightDao.addFlight(plane);
		tips = rows > 0 ? "添加成功" : "添加失败";
		return tips;
	}

	@Override
	public String deleteFlight(String delFlightNo) {
		String tips = "";
		int rows = flightDao.deleteFlight(delFlightNo);
		tips = rows > 0 ? "删除成功" : "删除失败";
		return tips;
	}

	@Override
	public void exportToTxt(List<Plane> flights, String txtPath) {
		flightDao.exportToTxt(flights, txtPath);
	}

	@Override
	public void saveToXML() {
		flightDao.saveToXML();
	}

}
